package com.itheima.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.mapper.DeptMapper;
import com.itheima.pojo.Dept;
import com.itheima.pojo.Emp;
import com.itheima.service.DeptService;
import com.itheima.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class DeptServiceImpl extends ServiceImpl<DeptMapper, Dept> implements DeptService {
    @Autowired
    @Lazy
    private EmpService empService;

    @Override
    public void removeDeptById(Integer id) {
        //根据部门id查询员工数量
        long count = empService.count(new LambdaQueryWrapper<Emp>().eq(Emp::getDeptId, id));
        if (count > 0) {
            throw new RuntimeException("当前部门有员工，不能删除");
        }

    }
}
